import { Common } from '../../utils/common.js';
var common = new Common();

let Wxparse = require("../../wxParse/wxParse.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    open_slide:'',
    open_first:'',
    open_second:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.id)
      var id = options.id;
    this.GetDetailInfo(id);
  },

  //获取对应文章类型详情
  GetDetailInfo: function (id){
    var data = {id: id};
    var that = this;
    var datas = {
      data : data,
      type:"post",
      url:"article"
    }
    common.DataToData(datas,data=>{
      that.setData({
        article_info:data,
        article_show: data.category_content[0].content,
      })
      wx.setNavigationBarTitle({
        title: that.data.article_info.title
      })
      Wxparse.wxParse('article', 'html', data.category_content[0].content, that, 5);
    })
  },

  //更改文章
  change_article:function(e){
    var article_info = this.data.article_info;
    var article_show = article_info[e.currentTarget.dataset.index];
    this.setData({
      article_show:article_show,
      open_slide: '',
    })
    Wxparse.wxParse('article', 'html', article_info.category_content[e.currentTarget.dataset.index].content, this, 5);
  },

  //导航
  open:function(e){
    var type = e.currentTarget.dataset.type;
    var key = 'open_' + type;
    if(type == 'slide') type = 'slide';
    else{
      var status = e.currentTarget.dataset.status;
      var status_key = 'shut_' + type;
      if (status == 'show'){
        status = 'shut';
        type = '';
      }else{
        status = 'show';
        type = 'open';
      }
      this.setData({
        [status_key]: status,
      })
    }
    this.setData({
      [key]:type,
    })
  }
})